package com.deyang.ui.activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.view.View;
import android.view.Window;


import com.deyang.application.MyApplication;
import com.deyang.ui.basepermissionui.BasePermissionActivity;
import com.deyang.util.ImageUtil;
import com.deyang.util.ToastUtil;

import java.util.List;


/**
 * 作者:王德阳
 * 创建时间:17/3/2
 * 描述:
 */
public abstract class BaseActivity extends BasePermissionActivity implements View.OnClickListener {
    protected String TAG;
    protected MyApplication mApp;
    private List<Activity> openActivityList;
    Window window;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TAG = this.getClass().getSimpleName();
        mApp = MyApplication.getApplication();
        initView(savedInstanceState);
        processLogic(savedInstanceState);
        setListener();
        openActivityList = mApp.getOpenActivityList();
        openActivityList.add(this);
        //RxBarTool.setTransparentStatusBar(this);//状态栏透明化

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        openActivityList.remove(this);
    }

    /**
     * 查找View
     *
     * @param id   控件的id
     * @param <VT> View类型
     * @return
     */
    protected <VT extends View> VT getViewById(@IdRes int id) {
        return (VT) findViewById(id);
    }

    /**
     * 初始化布局以及View控件
     */
    protected abstract void initView(Bundle savedInstanceState);

    /**
     * 处理业务逻辑，状态恢复等操作
     *
     * @param savedInstanceState
     */
    protected abstract void processLogic(Bundle savedInstanceState);

    /**
     * 给View控件添加事件监听器
     */
    public void setListener() {

    }

    /**
     * 需要处理点击事件时，重写该方法
     *
     * @param v
     */
    @Override
    public void onClick(View v) {
    }

    protected void showToastInfo(String text) {
        ToastUtil.showInfo(text);
    }

    protected void showToastError(String text) {
        ToastUtil.showError(text);
    }

    public int getColorRes(int res) {
        return getResources().getColor(res);
    }

    /**
     * 展示图片 跳转至展示图片页面
     *
     * @param images
     */
    public void showImage(String images, int position) {
        ImageUtil.showImages(this, images, position);
    }


}